<nz-card nzTitle="促销信息">
  <nz-descriptions
    nzBordered
    nzSize="small"
    class="detail-infos"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="前端标题">
      {{ detailDatas?.showCopy || '-' }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="备注">
      {{ detailDatas?.name || '-' }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="加价条件">
      单台机器回收价满 {{ detailDatas?.orderLimitMoney || '0' }} 元，加价 {{ detailDatas?.limitSmall || '0' }}
      <span *ngIf="detailDatas?.type === 2">%</span>
      <span *ngIf="detailDatas?.type === 1">元</span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="最高加价金额" *ngIf="detailDatas?.type === 2">
      {{ detailDatas?.limitBig || '0' }} 元
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="适用用户">
      <div [ngSwitch]="detailDatas?.userType">
        <div *ngSwitchCase="0">
          <nz-tag>通用</nz-tag>
        </div>
        <div *ngSwitchCase="1">
          <nz-tag [nzColor]="'#87d068'">C端</nz-tag>
        </div>
        <div *ngSwitchCase="2">
          <nz-tag [nzColor]="'#2db7f5'">B端</nz-tag>
        </div>
        <div *ngSwitchDefault>-</div>
      </div>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="适用成色">
      <div [ngSwitch]="detailDatas?.applyColour">
        <div *ngSwitchCase="0">全部</div>
        <div *ngSwitchCase="1">二手</div>
        <div *ngSwitchCase="2">准新</div>
        <div *ngSwitchDefault>-</div>
      </div>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="适用机型">
      <ng-container *ngIf="detailDatas?.containsModel == 0;else templateModel">
        全部
      </ng-container>
      <ng-template #templateModel>
        {{ strToArray(detailDatas?.containsModel) }} 个机型
        <button
          nz-button
          nzType="link"
          nzSize="small"
          (click)="selectMoreModel()"
        >查看</button>

        <!-- 机型select-tree -->
        <model-select-tree
          [(ngModel)]="isModelVisible"
          [defaultKeys]="defaultModelKeys"
          [disabled]="true"
        ></model-select-tree>
      </ng-template>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="促销状态">
      <span
        *ngIf="detailDatas.status || detailDatas.status == 0"
        [ngStyle]="{'color': detailDatas.status | makeupDescentListStatus: 'color'}">
        {{ detailDatas.status | makeupDescentListStatus: 'label' }}
      </span>
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="促销时间">
      {{ detailDatas?.beginTime || '----' }} ~ {{ detailDatas?.endTime || '----' }}
    </nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card nzTitle="使用统计" class="m-t-4">
  <nz-descriptions
    nzBordered
    nzSize="small"
    class="detail-infos"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="下单数量">{{ useStatistics?.selectCount || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="成交订单数">{{ useStatistics?.count || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="回收机器">{{ useStatistics?.machineCount || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="总成交金额">{{ useStatistics?.getProMachineSum || '0' }} 元</nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card nzTitle="使用记录" [nzExtra]="extraTemplate" class="m-t-4">
  <ng-template #extraTemplate>
    <div class="common-search-wrap">
      <!-- <div class="common-search-forms">
        <div class="common-form-item">
          <label class="common-search-label">订单状态</label>
          <div class="common-search-conrol">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="全部"
              [(ngModel)]="orderTableParams.state"
              (ngModelChange)="statusChange($event)">
              <nz-option
                *ngFor="let o of orderStateOptions"
                [nzLabel]="o.label"
                [nzValue]="o.id"
              ></nz-option>
            </nz-select>
          </div>
        </div>
      </div> -->
    </div>
  </ng-template>

  <div class="table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="orderTableParams.loading"
      [nzData]="orderTableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="orderTableParams.total"
      [nzPageIndex]="orderTableParams.page"
      [nzPageSize]="orderTableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="180px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="150px">订单状态</th>
          <th nzAlign="center" nzWidth="150px">用户ID</th>
          <th nzAlign="center" nzWidth="160px">下单机型</th>
          <th nzAlign="center" nzWidth="170px">预估合计</th>
          <th nzAlign="center" nzWidth="170px">验机合计</th>
          <!-- <th nzAlign="center" nzWidth="160px">加价促销</th> -->
          <th nzAlign="center" nzWidth="170px">下单时间</th>
          <th nzAlign="center" nzWidth="170px">成交时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="200px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 订单编号 -->
          <td nzAlign="center" nzLeft>{{ data?.okey || '-' }}</td>

          <!-- 订单状态 -->
          <td nzAlign="center">
            <span
              *ngIf="data.ostat || data.ostat == 0"
              [ngStyle]="{'color': data.ostat | orderState: 'color'}">
              {{ data.ostat | orderState: 'text' }}
            </span>
          </td>

          <!-- 用户ID -->
          <td nzAlign="center">
            <ng-container *ngIf="data.userId;else templateUser">
              <a
                nz-button
                nzType="link"
                nzSize="small"
                [routerLink]="['/customer/tabs', data.userId, 0]"
                target="_blank"
              >{{ data.userId }}</a>
            </ng-container>
            <ng-template #templateUser>
              游客
            </ng-template>
          </td>

          <!-- 下单机型 -->
          <td nzAlign="center">{{ data.umname || '-' }}</td>

          <!-- 预估合计 -->
          <td nzAlign="center">
            {{ (data.uprc || 0) + (data.orderAprc || 0) + (data.cprc || 0) }}
            <span *ngIf="data.orderAprc || data.cprc">（含加价{{ (data.orderAprc || 0) + (data.cprc || 0) }}）</span>
          </td>

          <!-- 验机合计 -->
          <td nzAlign="center">
            <p [ngStyle]="{'color': ((data.bprc || 0) + (data.aprc || 0)) < ((data.uprc || 0) + (data.orderAprc || 0)) ? '#FF0000' : ''}">
              {{ (data.bprc || 0) + (data.aprc || 0) + (data.cprc || 0) }}
              <span *ngIf="data.aprc || data.cprc">（含加价{{ (data.aprc || 0) + (data.cprc || 0) }}）</span>
            </p>
          </td>

          <!-- 加价促销 -->
          <!-- <td nzAlign="center">
            <ng-container *ngIf="data.activityId;else templateActivity">
              <a
                nz-button
                nzType="link"
                nzSize="small"
                target="_blank"
                [routerLink]="['/aisi-recyc/loveMakeupPromotionDetails']"
                [queryParams]="{type: 2, id: data.activityId}"
                target="_blank"
              >{{ data.activityName || '-' }}</a>
            </ng-container>
            <ng-template #templateActivity>
              -
            </ng-template>
          </td> -->

          <!-- 下单时间 -->
          <td nzAlign="center">{{ data.otime11 || '-' }}</td>

          <!-- 成交时间 -->
          <td nzAlign="center">{{ data.otime19 || '-' }}</td>

          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <a
              nz-button
              nzSize="small"
              nzType="link"
              target="_blank"
              [routerLink]="['/aisi-recyc/loveOrderDetails']"
              [queryParams]="{id: data.orderId}"
            >查看订单</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>